package ac.github.os.internal.core.condition.impl.location

import ac.github.os.internal.core.condition.Condition
import ac.github.os.internal.core.condition.call
import ac.github.os.internal.core.config.StringConfig
import ac.github.os.internal.core.config.get
import ac.github.os.internal.core.trigger.PlayerTrigger
import ac.github.os.internal.session.Session
import org.bukkit.Location
import taboolib.common.platform.Awake

@Awake
class RangeCondition : Condition {

    override fun doScreen(session: Session, config: StringConfig): Boolean {


        return session.call<PlayerTrigger> { trigger ->
            val location = config.get<Location>("loc") ?: return false
            val value = config.get<Double>("val") ?: return false
            location.world?.getNearbyEntities(location, value, value, value)?.any { it == trigger.player } ?: false
        }
    }

    override val namespace: String
        get() = "location:range"
}